package com.future.demo.web;

import com.alibaba.fastjson.JSONObject;
import com.future.rabbitmq.MessageDto;
import com.future.rabbitmq.SenderService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zou
 * @describe 测试发消息
 * @date 2018/8/29
 */
@Component
@Log4j2
@RestController
@RequestMapping("/api/socket")
public class WebSocketController {


    @Autowired
    private SenderService senderService;

    @GetMapping("/send/{tou}/{data}")
    public void publishWebSocket(@PathVariable String tou, @PathVariable String data) {
        log.info("Publis the result : " + data);
        JSONObject object = new JSONObject();
        object.put("tou", tou);
        object.put("value", data);
        MessageDto dto = new MessageDto();
        dto.setType(1);
        dto.setData(object);
        dto.setReceiver(2);
        senderService.send(dto);
    }

}
